Use g_slice instead of mem chunks.
authorMatthias Clasen <mclasen@redhat.com>
Mon, 5 Dec 2005 21:28:32 +0000 (21:28 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 5 Dec 2005 21:28:32 +0000 (21:28 +0000)
2005-12-05  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtkwidget.c:
* gtk/gtkuimanager.c:
* gtk/gtktreedatalist.c:
* gtk/gtktext.c:
* gtk/gtkmain.c:
* gtk/gtkitemfactory.c:
* gtk/gtkseparator.[hc]:
* gtk/gtkclist.[hc]:
* gtk/gtkctree.c:
* gtk/gtkgc.c: Use g_slice instead of mem chunks.

12 files changed:
ChangeLog
ChangeLog.pre-2-10
gtk/gtkclist.c
gtk/gtkclist.h
gtk/gtkctree.c
gtk/gtkgc.c
gtk/gtkitemfactory.c
gtk/gtkmain.c
gtk/gtktext.c
gtk/gtktreedatalist.c
gtk/gtkuimanager.c
gtk/gtkwidget.c

index d1f3217f01ffd75d6241952991a624ddd57ad658..6f3868a2941a8abb95bc48f79c455cefdcb26ccc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-12-05  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkwidget.c: 
+       * gtk/gtkuimanager.c: 
+       * gtk/gtktreedatalist.c: 
+       * gtk/gtktext.c: 
+       * gtk/gtkmain.c: 
+       * gtk/gtkitemfactory.c: 
+       * gtk/gtkseparator.[hc]:
+       * gtk/gtkclist.[hc]: 
+       * gtk/gtkctree.c:
+       * gtk/gtkgc.c: Use g_slice instead of mem chunks.
+
 2005-12-05  Michael Natterer  <mitch@imendio.com>
 
        * gdk/x11/gdkevents-x11.c: map the new GtkSettings properties
index d1f3217f01ffd75d6241952991a624ddd57ad658..6f3868a2941a8abb95bc48f79c455cefdcb26ccc 100644 (file)
@@ -1,3 +1,16 @@
+2005-12-05  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtkwidget.c: 
+       * gtk/gtkuimanager.c: 
+       * gtk/gtktreedatalist.c: 
+       * gtk/gtktext.c: 
+       * gtk/gtkmain.c: 
+       * gtk/gtkitemfactory.c: 
+       * gtk/gtkseparator.[hc]:
+       * gtk/gtkclist.[hc]: 
+       * gtk/gtkctree.c:
+       * gtk/gtkgc.c: Use g_slice instead of mem chunks.
+
 2005-12-05  Michael Natterer  <mitch@imendio.com>
 
        * gdk/x11/gdkevents-x11.c: map the new GtkSettings properties
index 8b636003d9730f36ef944c45952272fe6fe9d6ba..71f2ddbfea6be4e15a0247c133ab919d264f4f90 100644 (file)
@@ -46,9 +46,6 @@
 /* length of button_actions array */
 #define MAX_BUTTON 5
 
-/* the number rows memchunk expands at a time */
-#define CLIST_OPTIMUM_SIZE 64
-
 /* the width of the column resize windows */
 #define DRAG_WIDTH  6
 
@@ -1014,9 +1011,6 @@ gtk_clist_init (GtkCList *clist)
   GTK_CLIST_SET_FLAG (clist, CLIST_DRAW_DRAG_LINE);
   GTK_CLIST_SET_FLAG (clist, CLIST_USE_DRAG_ICONS);
 
-  clist->row_mem_chunk = NULL;
-  clist->cell_mem_chunk = NULL;
-
   clist->freeze_count = 0;
 
   clist->rows = 0;
@@ -1092,23 +1086,6 @@ gtk_clist_constructor (GType                  type,
                                                                construct_properties);
   GtkCList *clist = GTK_CLIST (object);
   
-  /* initalize memory chunks, if this has not been done by any
-   * possibly derived widget
-   */
-  if (!clist->row_mem_chunk)
-    clist->row_mem_chunk = g_mem_chunk_new ("clist row mem chunk",
-                                           sizeof (GtkCListRow),
-                                           sizeof (GtkCListRow) *
-                                           CLIST_OPTIMUM_SIZE, 
-                                           G_ALLOC_AND_FREE);
-  
-  if (!clist->cell_mem_chunk)
-    clist->cell_mem_chunk = g_mem_chunk_new ("clist cell mem chunk",
-                                            sizeof (GtkCell) * clist->columns,
-                                            sizeof (GtkCell) * clist->columns *
-                                            CLIST_OPTIMUM_SIZE, 
-                                            G_ALLOC_AND_FREE);
-  
   /* allocate memory for columns */
   clist->column = columns_new (clist);
   
@@ -4438,9 +4415,6 @@ gtk_clist_finalize (GObject *object)
 
   columns_delete (clist);
 
-  g_mem_chunk_destroy (clist->cell_mem_chunk);
-  g_mem_chunk_destroy (clist->row_mem_chunk);
-
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -6374,8 +6348,8 @@ row_new (GtkCList *clist)
   int i;
   GtkCListRow *clist_row;
 
-  clist_row = g_chunk_new (GtkCListRow, clist->row_mem_chunk);
-  clist_row->cell = g_chunk_new (GtkCell, clist->cell_mem_chunk);
+  clist_row = g_slice_new (GtkCListRow);
+  clist_row->cell = g_slice_new (GtkCell);
 
   for (i = 0; i < clist->columns; i++)
     {
@@ -6424,8 +6398,8 @@ row_delete (GtkCList    *clist,
   if (clist_row->destroy)
     clist_row->destroy (clist_row->data);
 
-  g_mem_chunk_free (clist->cell_mem_chunk, clist_row->cell);
-  g_mem_chunk_free (clist->row_mem_chunk, clist_row);
+  g_slice_free (GtkCell, clist_row->cell);
+  g_slice_free (GtkCListRow, clist_row);
 }
 
 /* FOCUS FUNCTIONS
index 6d5ca31a7e660fd48bc582dca2b420f6f93bd0d6..5375ea1c2eb2c78e620b32d2e6a1bc445f58515d 100644 (file)
@@ -151,9 +151,8 @@ struct _GtkCList
   
   guint16 flags;
   
-  /* mem chunks */
-  GMemChunk *row_mem_chunk;
-  GMemChunk *cell_mem_chunk;
+  gpointer reserved1;
+  gpointer reserved2;
 
   guint freeze_count;
   
index 0fe8ba7678bb5b6507cde221b00c8ebfd012b3c7..86845d7d777c451d9f6c1cb0d3e0f5bcb6360b97 100644 (file)
@@ -567,24 +567,12 @@ gtk_ctree_set_arg (GtkObject      *object,
   switch (arg_id)
     {
     case ARG_N_COLUMNS: /* construct-only arg, only set at construction time */
-      g_return_if_fail (clist->row_mem_chunk == NULL);
       clist->columns = MAX (1, GTK_VALUE_UINT (*arg));
-      clist->row_mem_chunk = g_mem_chunk_new ("ctree row mem chunk",
-                                             sizeof (GtkCTreeRow),
-                                             sizeof (GtkCTreeRow)
-                                             * CLIST_OPTIMUM_SIZE,
-                                             G_ALLOC_AND_FREE);
-      clist->cell_mem_chunk = g_mem_chunk_new ("ctree cell mem chunk",
-                                              sizeof (GtkCell) * clist->columns,
-                                              sizeof (GtkCell) * clist->columns
-                                              * CLIST_OPTIMUM_SIZE,
-                                              G_ALLOC_AND_FREE);
       ctree->tree_column = CLAMP (ctree->tree_column, 0, clist->columns);
       break;
     case ARG_TREE_COLUMN: /* construct-only arg, only set at construction time */
       ctree->tree_column = GTK_VALUE_UINT (*arg);
-      if (clist->row_mem_chunk)
-       ctree->tree_column = CLAMP (ctree->tree_column, 0, clist->columns);
+      ctree->tree_column = CLAMP (ctree->tree_column, 0, clist->columns);
       break;
     case ARG_INDENT:
       gtk_ctree_set_indent (ctree, GTK_VALUE_UINT (*arg));
@@ -3207,8 +3195,8 @@ row_new (GtkCTree *ctree)
   int i;
 
   clist = GTK_CLIST (ctree);
-  ctree_row = g_chunk_new (GtkCTreeRow, clist->row_mem_chunk);
-  ctree_row->row.cell = g_chunk_new (GtkCell, clist->cell_mem_chunk);
+  ctree_row = g_slice_new (GtkCTreeRow);
+  ctree_row->row.cell = g_slice_new (GtkCell);
 
   for (i = 0; i < clist->columns; i++)
     {
@@ -3294,8 +3282,8 @@ row_delete (GtkCTree    *ctree,
       dnotify (ddata);
     }
 
-  g_mem_chunk_free (clist->cell_mem_chunk, ctree_row->row.cell);
-  g_mem_chunk_free (clist->row_mem_chunk, ctree_row);
+  g_slice_free (GtkCell, ctree_row->row.cell);
+  g_slice_free (GtkCListRow, ctree_row);
 }
 
 static void
index 4073ed384a7b67e292e7e77d89a3b8136e93fc16..a2cf6e4c051569f8c42f09f2fafbb35ca5d0f041 100644 (file)
@@ -65,8 +65,6 @@ static gint      gtk_gc_drawable_equal   (GtkGCDrawable *a,
 static gint initialize = TRUE;
 static GCache *gc_cache = NULL;
 
-static GMemChunk *key_mem_chunk = NULL;
-
 
 GdkGC*
 gtk_gc_get (gint             depth,
@@ -143,11 +141,7 @@ gtk_gc_key_dup (GtkGCKey *key)
 {
   GtkGCKey *new_key;
 
-  if (!key_mem_chunk)
-    key_mem_chunk = g_mem_chunk_new ("key mem chunk", sizeof (GtkGCKey),
-                                    1024, G_ALLOC_AND_FREE);
-
-  new_key = g_chunk_new (GtkGCKey, key_mem_chunk);
+  new_key = g_slice_new (GtkGCKey);
 
   *new_key = *key;
 
@@ -157,7 +151,7 @@ gtk_gc_key_dup (GtkGCKey *key)
 static void
 gtk_gc_key_destroy (GtkGCKey *key)
 {
-  g_mem_chunk_free (key_mem_chunk, key);
+  g_slice_free (GtkGCKey, key);
 }
 
 static gpointer
index 2bfc856f9e787e7b7fd70a5e7ecb8332f2826659..aafb876232160863f1d5950f7536d7d302d5131e 100644 (file)
@@ -84,8 +84,6 @@ static void   gtk_item_factory_finalize               (GObject              *object);
 static GtkItemFactoryClass *gtk_item_factory_class = NULL;
 static gpointer          parent_class = NULL;
 static const gchar      item_factory_string[] = "Gtk-<ItemFactory>";
-static GMemChunk       *ifactory_item_chunks = NULL;
-static GMemChunk       *ifactory_cb_data_chunks = NULL;
 static GQuark           quark_popup_data = 0;
 static GQuark           quark_if_menu_pos = 0;
 static GQuark           quark_item_factory = 0;
@@ -148,16 +146,6 @@ gtk_item_factory_class_init (GtkItemFactoryClass  *class)
   object_class->destroy = gtk_item_factory_destroy;
 
   class->item_ht = g_hash_table_new (g_str_hash, g_str_equal);
-  ifactory_item_chunks =
-    g_mem_chunk_new ("GtkItemFactoryItem",
-                    sizeof (GtkItemFactoryItem),
-                    sizeof (GtkItemFactoryItem) * ITEM_BLOCK_SIZE,
-                    G_ALLOC_ONLY);
-  ifactory_cb_data_chunks =
-    g_mem_chunk_new ("GtkIFCBData",
-                    sizeof (GtkIFCBData),
-                    sizeof (GtkIFCBData) * ITEM_BLOCK_SIZE,
-                    G_ALLOC_AND_FREE);
 
   quark_popup_data             = g_quark_from_static_string ("GtkItemFactory-popup-data");
   quark_if_menu_pos            = g_quark_from_static_string ("GtkItemFactory-menu-position");
@@ -289,7 +277,7 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
   item = g_hash_table_lookup (class->item_ht, full_path);
   if (!item)
     {
-      item = g_chunk_new (GtkItemFactoryItem, ifactory_item_chunks);
+      item = g_slice_new (GtkItemFactoryItem);
 
       item->path = g_strdup (full_path);
       item->widgets = NULL;
@@ -333,7 +321,7 @@ gtk_item_factory_add_foreign (GtkWidget      *accel_widget,
 static void
 ifactory_cb_data_free (gpointer mem)
 {
-  g_mem_chunk_free (ifactory_cb_data_chunks, mem);
+  g_slice_free (GtkIFCBData, mem);
 }
 
 static void
@@ -369,7 +357,7 @@ gtk_item_factory_add_item (GtkItemFactory           *ifactory,
     {
       GtkIFCBData *data;
 
-      data = g_chunk_new (GtkIFCBData, ifactory_cb_data_chunks);
+      data = g_slice_new (GtkIFCBData);
       data->func = callback;
       data->callback_type = callback_type;
       data->func_data = callback_data;
index c42a3509b6d96255cf02f8737f38d352b1c9c7cf..3f9f54d98d8b311e28b3f372c805012a306fe05c 100644 (file)
@@ -144,8 +144,6 @@ static GList *init_functions = NULL;           /* A list of init functions.
                                            */
 static GList *quit_functions = NULL;      /* A list of quit functions.
                                            */
-static GMemChunk *quit_mem_chunk = NULL;
-
 static GSList *key_snoopers = NULL;
 
 guint gtk_debug_flags = 0;                /* Global GTK debug flag */
@@ -1693,11 +1691,7 @@ gtk_quit_add_full (guint         main_level,
   
   g_return_val_if_fail ((function != NULL) || (marshal != NULL), 0);
 
-  if (!quit_mem_chunk)
-    quit_mem_chunk = g_mem_chunk_new ("quit mem chunk", sizeof (GtkQuitFunction),
-                                     512, G_ALLOC_AND_FREE);
-  
-  quitf = g_chunk_new (GtkQuitFunction, quit_mem_chunk);
+  quitf = g_slice_new (GtkQuitFunction);
   
   quitf->id = quit_id++;
   quitf->main_level = main_level;
@@ -1716,7 +1710,7 @@ gtk_quit_destroy (GtkQuitFunction *quitf)
 {
   if (quitf->destroy)
     quitf->destroy (quitf->data);
-  g_mem_chunk_free (quit_mem_chunk, quitf);
+  g_slice_free (GtkQuitFunction, quitf);
 }
 
 static gint
index 643c034199e00f50eab9aae4ba0761bfade81ed1..03f339f7067d99d089179a462a7968ab80913a98 100644 (file)
@@ -442,10 +442,6 @@ static void gtk_text_show_props (GtkText* test,
 #define TEXT_SHOW_ADJ(text,adj,msg)
 #endif
 
-/* Memory Management. */
-static GMemChunk  *params_mem_chunk    = NULL;
-static GMemChunk  *text_property_chunk = NULL;
-
 static GtkWidgetClass *parent_class = NULL;
 
 
@@ -735,12 +731,6 @@ gtk_text_init (GtkText *text)
  
   text->freeze_count = 0;
   
-  if (!params_mem_chunk)
-    params_mem_chunk = g_mem_chunk_new ("LineParams",
-                                       sizeof (LineParams),
-                                       256 * sizeof (LineParams),
-                                       G_ALLOC_AND_FREE);
-  
   text->default_tab_width = 4;
   text->tab_stops = NULL;
   
@@ -2293,7 +2283,7 @@ line_params_iterate (GtkText* text,
   for (;;)
     {
       if (alloc)
-       lp = g_chunk_new (LineParams, params_mem_chunk);
+       lp = g_slice_new (LineParams);
       else
        lp = &lpbuf;
       
@@ -2977,15 +2967,7 @@ new_text_property (GtkText *text, GdkFont *font, const GdkColor* fore,
 {
   TextProperty *prop;
   
-  if (text_property_chunk == NULL)
-    {
-      text_property_chunk = g_mem_chunk_new ("text property mem chunk",
-                                            sizeof(TextProperty),
-                                            1024*sizeof(TextProperty),
-                                            G_ALLOC_AND_FREE);
-    }
-  
-  prop = g_chunk_new(TextProperty, text_property_chunk);
+  prop = g_slice_new (TextProperty);
 
   prop->flags = 0;
   if (font)
@@ -3022,7 +3004,7 @@ destroy_text_property (TextProperty *prop)
   if (prop->font)
     text_font_unref (prop->font);
   
-  g_mem_chunk_free (text_property_chunk, prop);
+  g_slice_free (TextProperty, prop);
 }
 
 /* Flop the memory between the point and the gap around like a
@@ -3778,7 +3760,7 @@ free_cache (GtkText* text)
     }
   
   for (; cache; cache = cache->next)
-    g_mem_chunk_free (params_mem_chunk, cache->data);
+    g_slice_free (LineParams, cache->data);
   
   g_list_free (text->line_start_cache);
   
@@ -3804,7 +3786,7 @@ remove_cache_line (GtkText* text, GList* member)
   
   list = member->next;
   
-  g_mem_chunk_free (params_mem_chunk, member->data);
+  g_slice_free (LineParams, member->data);
   g_list_free_1 (member);
   
   return list;
index a70a53d8205858a459b94d996d06de3435fc80ab..9cbd26a7aaa4d06e2cf2815885cfb9e0e4c9cba9 100644 (file)
@@ -24,8 +24,6 @@
 #include "gtktreedatalist.h"
 #include "gtkalias.h"
 #include <string.h>
-static GMemChunk *tree_chunk = NULL;
-#define TREE_CHUNK_PREALLOCS 64
 
 /* node allocation
  */
@@ -34,14 +32,7 @@ _gtk_tree_data_list_alloc (void)
 {
   GtkTreeDataList *list;
 
-  if (tree_chunk == NULL)
-    tree_chunk = g_mem_chunk_new ("treedatalist mem chunk",
-                                 sizeof (GtkTreeDataList),
-                                 sizeof (GtkTreeDataList) * TREE_CHUNK_PREALLOCS,
-                                 G_ALLOC_AND_FREE);
-
-  list = g_chunk_new (GtkTreeDataList, tree_chunk);
-  memset (list, 0, sizeof (GtkTreeDataList));
+  list = g_slice_new0 (GtkTreeDataList);
 
   return list;
 }
@@ -65,7 +56,7 @@ _gtk_tree_data_list_free (GtkTreeDataList *list,
       else if (g_type_is_a (column_headers [i], G_TYPE_BOXED) && tmp->data.v_pointer != NULL)
        g_boxed_free (column_headers [i], (gpointer) tmp->data.v_pointer);
 
-      g_mem_chunk_free (tree_chunk, tmp);
+      g_slice_free (GtkTreeDataList, tmp);
       i++;
       tmp = next;
     }
index c624ba89857b4dc43280b3814f48b13819f69737..c07b193f3013f2fa1e3054b90c218c26465869f1 100644 (file)
@@ -166,8 +166,6 @@ enum
 static GObjectClass *parent_class = NULL;
 static guint ui_manager_signals[LAST_SIGNAL] = { 0 };
 
-static GMemChunk *merge_node_chunk = NULL;
-
 GType
 gtk_ui_manager_get_type (void)
 {
@@ -205,10 +203,6 @@ gtk_ui_manager_class_init (GtkUIManagerClass *klass)
 
   gobject_class = G_OBJECT_CLASS (klass);
 
-  if (!merge_node_chunk)
-    merge_node_chunk = g_mem_chunk_create (Node, 64,
-                                          G_ALLOC_AND_FREE);
-
   gobject_class->finalize = gtk_ui_manager_finalize;
   gobject_class->set_property = gtk_ui_manager_set_property;
   gobject_class->get_property = gtk_ui_manager_get_property;
@@ -893,7 +887,7 @@ get_child_node (GtkUIManager *self,
        {
          Node *mnode;
          
-         mnode = g_chunk_new0 (Node, merge_node_chunk);
+         mnode = g_slice_new0 (Node);
          mnode->type = node_type;
          mnode->name = g_strndup (childname, childname_length);
 
@@ -933,7 +927,7 @@ get_child_node (GtkUIManager *self,
        {
          Node *mnode;
 
-         mnode = g_chunk_new0 (Node, merge_node_chunk);
+         mnode = g_slice_new0 (Node);
          mnode->type = node_type;
          mnode->name = g_strndup (childname, childname_length);
          mnode->dirty = TRUE;
@@ -1001,7 +995,7 @@ free_node (GNode *node)
   if (info->extra)
     g_object_unref (info->extra);
   g_free (info->name);
-  g_chunk_free (info, merge_node_chunk);
+  g_slice_free (Node, info);
 
   return FALSE;
 }
index 2ee47887f0a8833eeeda9e7fb426d5ca39080c85..fc01393cdfdd971201beaa569501f0d38213c408 100644 (file)
@@ -236,7 +236,6 @@ static void gtk_widget_get_draw_rectangle (GtkWidget    *widget,
 /* --- variables --- */
 static gpointer         parent_class = NULL;
 static guint            widget_signals[LAST_SIGNAL] = { 0 };
-static GMemChunk       *aux_info_mem_chunk = NULL;
 static GtkStyle        *gtk_default_style = NULL;
 static GSList          *colormap_stack = NULL;
 static guint            composite_child_stack = 0;
@@ -6942,11 +6941,7 @@ _gtk_widget_get_aux_info (GtkWidget *widget,
   aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
   if (!aux_info && create)
     {
-      if (!aux_info_mem_chunk)
-       aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
-                                             sizeof (GtkWidgetAuxInfo),
-                                             1024, G_ALLOC_AND_FREE);
-      aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
+      aux_info = g_slice_new (GtkWidgetAuxInfo);
 
       aux_info->width = -1;
       aux_info->height = -1;
@@ -6971,7 +6966,7 @@ _gtk_widget_get_aux_info (GtkWidget *widget,
 static void
 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
 {
-  g_mem_chunk_free (aux_info_mem_chunk, aux_info);
+  g_slice_free (GtkWidgetAuxInfo, aux_info);
 }
 
 static void